package com.ncloud.system.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ncloud.system.entity.UserAuth;

@Mapper
public interface UserAuthMapper {

	@Insert("insert into sys_user_auth(user_id, auth_code, eff_date, exp_date)"
			+ "values(#{userId}, #{authCode}, #{effDate}, #{expDate})")
	void save(UserAuth userAuth);

	@Update("update sys_user_auth set exp_date = now() where auth_code = #{authCode} and now() between eff_date and exp_date")
	void expire(String authCode);

	@Select("select user_id,auth_code from sys_user_auth where user_id = #{userId} and now() between eff_date and exp_date")
	@Results({ @Result(column = "user_id", property = "userId"), @Result(column = "auth_code", property = "authCode")})
	List<UserAuth> getAuthsByUserId(Long userId);

}
